var WR1D_angs = [85, 80, 75, 70, 65, 60, 55];
var WR1D_dis = [1401, 2126, 3064, 3887, 4591, 5175, 5626];

//根据高程获取射程增量系数
function getScale(height){
	var scale = 1.0;
	if (height <= 500) {
		scale = 1.0;
	} else if (height <= 1000) {
		scale = 1.05;
	} else if (height <= 1500) {
		scale = 1.10;
	} else if (height <= 2000) {
		scale = 1.15;
	} else if (height <= 2500) {
		scale = 1.20;
	} else {
		scale = 1.25;
	}
	
	return scale;
}

/**
 * 计算发射仰角范围、方位角范围
 * @param {Object} height
 * @param {Object} startR
 * @param {Object} endR
 * @param {Object} startAngle
 * @param {Object} endAngle
 */
function getAZEle(height,startR,endR,startAngle,endAngle){
	var datas=[];
	if(endR<=startR ||endAngle<=startAngle){
		return datas;
	}
	if(startR<WR1D_dis[0].scale||endR>WR1D_dis[WR1D_dis.length-1].scale){
		//距离参数不符合规范
		return datas;
	}
	var scale=getScale(height);
	var startIndex=0;
	var endIndex=0;
	for(var i=0;i<WR1D_dis.length-1;i++){
		var min=WR1D_dis[i]*scale;
		var max=WR1D_dis[i+1]*scale;
		if(startR>=min&&startR<=max){
			//代表在这个区间
			startIndex=i;
		}
		if(endR>=min&&endR<=max){
			//代表在这个区间
			endIndex=i;
		}
	}
	var maxEle=lineDiff(WR1D_dis[startIndex]*scale,WR1D_dis[startIndex+1]*scale,WR1D_angs[startIndex],WR1D_angs[startIndex+1],startR);
	maxEle=Math.trunc(maxEle);
	var minEle=lineDiff(WR1D_dis[endIndex]*scale,WR1D_dis[endIndex+1]*scale,WR1D_angs[endIndex],WR1D_angs[endIndex+1],endR);
	minEle=Math.ceil(minEle);
	
	var minAZ=Math.ceil(startAngle);
	var maxAZ=Math.trunc(endAngle);
	 datas=[minEle,maxEle,minAZ,maxAZ];
	return datas;
}
//获取线性插值的数据
function lineDiff(x1,x2,y1,y2,value){
	return ((y2-y1)/(x2-x1))*value+((y1*x2-y2*x1)/(x2-x1));
}



//获取方位角
function getAZ(startAngle,endAngle){
	var minAZ=Math.ceil(startAngle);
	var maxAZ=Math.trunc(endAngle);
	return [minAZ,maxAZ];
}